package cn.cs.yangtai.controller;

import cn.cs.yangtai.entity.Comminicate;
import cn.cs.yangtai.entity.Expert;
import cn.cs.yangtai.entity.vo.PageResult;
import cn.cs.yangtai.entity.vo.ResponsePojo;
import cn.cs.yangtai.service.ExpertService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

import static cn.cs.yangtai.entity.vo.ResponsePojo.success;

/**
 * 专家表(Expert)表控制层
 *
 * @author makejava
 * @since 2024-12-17 13:11:17
 */
@RestController
@CrossOrigin
@RequestMapping("expert")
@Tag(name = "专家信息")
public class ExpertController {
    /**
     * 服务对象
     */
    @Resource
    private ExpertService expertService;

    /**
     * 专家列表
     *
     * @param cuttentPage 本页
     * @param pageSize    分页大小
     * @return 查询结果
     */
    @GetMapping
    @Operation(summary = "分页查询所有专家信息")
    public ResponsePojo<PageResult<Expert>> queryByPage(Integer cuttentPage, Integer pageSize) {
        PageResult<Expert> result=expertService.queryByPage(cuttentPage,pageSize);
        return ResponsePojo.success(result,"分页查询专家成功");
    }
    /**
     * 通过条件查询专家
     *
     * @param expert 查询条件
     * @return 单条数据
     */
    @GetMapping("searchByCondition")
    @Operation(summary = "根据条件查询专家")
    public ResponsePojo<List<Expert>> searchByCondition(@RequestBody Expert expert) {
        List<Expert> result=this.expertService.queryByCondition(expert);
        return ResponsePojo.success(result,"条件查专家成功");
    }
    /**
     * 专家推荐(4分以上可附加领域)
     *
     * @param field 专家领域，如无，可传null
     * @return 编辑结果
     */
    @GetMapping("recommend")
    @Operation(summary = "推荐专家10人及以下")
    public ResponsePojo<List<Expert>> recommend(String field) {
        List<Expert> expert=this.expertService.recommend(field);
        return ResponsePojo.success(expert,"推荐专家");
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @Operation(summary = "根据ID查询专家信息")
    @GetMapping("{id}")
    public ResponseEntity<Expert> queryById(@PathVariable("id") Integer id) {
        return ResponseEntity.ok(this.expertService.queryById(id));
    }

    /**
     * 新增数据
     *
     * @return 新增结果
     */
//    @PostMapping
    public ResponseEntity<Expert> add(Integer eUserid,String eName,float eScore,String eIntroduction,String eField) {
        Expert expert=new Expert();
        expert.setEUserid(eUserid);
        expert.setEName(eName);
        expert.setEScore(eScore);
        expert.setEIntroduction(eIntroduction);
        expert.setEField(eField);
        return ResponseEntity.ok(this.expertService.insert(expert));
    }

    /**
     * 编辑数据
     *
     * @return 编辑结果
     */
    @PutMapping
    public ResponseEntity<Expert> edit(Integer eXpertId,Integer eUserid,String eName,float eScore,String eIntroduction,String eField) {
        Expert expert=new Expert();
        expert.setEXpertId(eXpertId);
        expert.setEUserid(eUserid);
        expert.setEName(eName);
        expert.setEScore(eScore);
        expert.setEIntroduction(eIntroduction);
        expert.setEField(eField);
        return ResponseEntity.ok(this.expertService.update(expert));
    }

    /**
     * 删除数据
     *
     * @param id 主键
     * @return 删除是否成功
     */
//    @DeleteMapping
    public ResponseEntity<Boolean> deleteById(Integer id) {
        return ResponseEntity.ok(this.expertService.deleteById(id));
    }

}

